package com.ourteam.product.ui.dao.impl;

import com.ourteam.product.ui.dao.IProductUITabItemDAO;
import com.ourteam.product.ui.dao.ProductUITabItem;
import com.ourteam.product.ui.dao.ProductUITabItemDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-12-14 15:15:18 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractProductUITabItemDAOJdbcImpl extends AbstractSpringDAO
    implements IProductUITabItemDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        TabId,
        FormId,
        Code,
        Title,
        TitleKey,
        Icon,
        CompentClass,
        SortIndex,
        LastModifyUser,
        LastModifyTime,
        Status,
        Remarks,
        FormCode
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.TabId,
        _DataObjectProperty.FormId,
        _DataObjectProperty.Code,
        _DataObjectProperty.Title,
        _DataObjectProperty.TitleKey,
        _DataObjectProperty.Icon,
        _DataObjectProperty.CompentClass,
        _DataObjectProperty.SortIndex,
        _DataObjectProperty.LastModifyUser,
        _DataObjectProperty.LastModifyTime,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.FormCode
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<ProductUITabItem, ProductUITabItemDAOQueryBean> daoHelper;

  public AbstractProductUITabItemDAOJdbcImpl() {
    super();
    daoHelper = new DataAccessObjectHelper<ProductUITabItem, ProductUITabItemDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIFormDAO.EntityName)
          .append(" PRODUCT_UI_FORM ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIFormDAO.Id,
              com.ourteam.product.ui.dao.IProductUIFormDAO.EntityName + ".",
              "PRODUCT_UI_FORM."));
      relatedJoinSQLBuffer.append(" = ").append(FormId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aProductUITabItem
   * @throws Exception
   */
  public boolean checkIsUnique(ProductUITabItem aProductUITabItem) throws Exception {

    if (aProductUITabItem == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aProductUITabItem.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aProductUITabItem
   * @throws Exception
   */
  public void insert(ProductUITabItem aProductUITabItem) throws Exception {

    PropertyUtils.setProperty(
        aProductUITabItem,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    super.doInsert(aProductUITabItem);
  }

  /**
   * Batch Insert Datas
   *
   * @param aProductUITabItem
   * @throws Exception
   */
  public void batchInsert(ProductUITabItem[] aProductUITabItems) throws Exception {

    super.doBatchInsert(aProductUITabItems);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(ProductUITabItemDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(ProductUITabItem aProductUITabItem) throws Exception {

    delete(aProductUITabItem.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aProductUITabItem
   * @throws Exception
   */
  public void update(ProductUITabItem aProductUITabItem) throws Exception {

    PropertyUtils.setProperty(
        aProductUITabItem,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    if (aProductUITabItem.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aProductUITabItem);

    ProductUITabItem tempObj = findById(aProductUITabItem.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aProductUITabItem, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aProductUITabItems[]
   * @throws Exception
   */
  public void batchUpdate(ProductUITabItem[] aProductUITabItems) throws Exception {

    super.doBatchUpdate(aProductUITabItems);
  }

  /**
   * Update Data By Condictions
   *
   * @param aProductUITabItem
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(ProductUITabItem aProductUITabItem, ProductUITabItemDAOQueryBean aQueryBean)
      throws Exception {

    PropertyUtils.setProperty(
        aProductUITabItem,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    super.doUpdateByQuery(aProductUITabItem, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(ProductUITabItemDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(ProductUITabItem aProductUITabItem) throws Exception {

    if (aProductUITabItem.getCode() == null) {
      throw new Exception("The ProductUITabItem.code value is not allow NULL");
    }

    if (aProductUITabItem.getTitle() == null) {
      throw new Exception("The ProductUITabItem.title value is not allow NULL");
    }

    if (aProductUITabItem.getTitleKey() == null) {
      throw new Exception("The ProductUITabItem.titleKey value is not allow NULL");
    }

    if (aProductUITabItem.getIcon() == null) {
      throw new Exception("The ProductUITabItem.icon value is not allow NULL");
    }

    if (aProductUITabItem.getCompentClass() == null) {
      throw new Exception("The ProductUITabItem.compentClass value is not allow NULL");
    }

    if (aProductUITabItem.getLastModifyUser() == null) {
      throw new Exception("The ProductUITabItem.lastModifyUser value is not allow NULL");
    }

    if (aProductUITabItem.getLastModifyTime() == null) {
      throw new Exception("The ProductUITabItem.lastModifyTime value is not allow NULL");
    }

    if (aProductUITabItem.getStatus() == null) {
      throw new Exception("The ProductUITabItem.status value is not allow NULL");
    }

    if (aProductUITabItem.getRemarks() == null) {
      throw new Exception("The ProductUITabItem.remarks value is not allow NULL");
    }

    if (aProductUITabItem.getFormCode() == null) {
      throw new Exception("The ProductUITabItem.formCode value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public ProductUITabItem findById(final long id) throws Exception {

    ProductUITabItemDAOQueryBean queryBean = new ProductUITabItemDAOQueryBean();

    ProductUITabItemDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    ProductUITabItem[] ProductUITabItems = query(queryBean);

    if (ProductUITabItems.length == 0) {
      return null;
    } else {
      return ProductUITabItems[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return ProductUITabItem[]
   * @throws Exception
   */
  public ProductUITabItem[] query(ProductUITabItemDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcProductUITabItemRowMapper());

    return (ProductUITabItem[]) result.toArray(new ProductUITabItem[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(ProductUITabItemDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(ProductUITabItemDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      ProductUITabItem[] aProductUITabItems, ProductUITabItemDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aProductUITabItems, queryBean);
  }

  public void synchronize(
      ProductUITabItem[] aProductUITabItems,
      ProductUITabItemDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<ProductUITabItem> callBack)
      throws Exception {
    daoHelper.synchronize(aProductUITabItems, queryBean, callBack);
  }

  public static class JdbcProductUITabItemRowMapper implements RowMapper<ProductUITabItem> {

    public ProductUITabItem mapRow(ResultSet resultSet, int arg1) throws SQLException {
      ProductUITabItem object = new ProductUITabItem();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object tabId = null;

        tabId = resultSet.getObject(columnIndex++);

        object.setTabIdNull(resultSet.getBoolean(columnIndex++));

        if (tabId != null) {

          setBeanValue(object, _DataObjectProperty.TabId, tabId);
        }

        Object formId = null;

        formId = resultSet.getObject(columnIndex++);

        object.setFormIdNull(resultSet.getBoolean(columnIndex++));

        if (formId != null) {

          setBeanValue(object, _DataObjectProperty.FormId, formId);
        }

        Object code = null;

        code = resultSet.getObject(columnIndex++);

        object.setCodeNull(resultSet.getBoolean(columnIndex++));

        if (code != null) {

          setBeanValue(object, _DataObjectProperty.Code, code);
        }

        Object title = null;

        title = resultSet.getObject(columnIndex++);

        object.setTitleNull(resultSet.getBoolean(columnIndex++));

        if (title != null) {

          setBeanValue(object, _DataObjectProperty.Title, title);
        }

        Object titleKey = null;

        titleKey = resultSet.getObject(columnIndex++);

        object.setTitleKeyNull(resultSet.getBoolean(columnIndex++));

        if (titleKey != null) {

          setBeanValue(object, _DataObjectProperty.TitleKey, titleKey);
        }

        Object icon = null;

        icon = resultSet.getObject(columnIndex++);

        object.setIconNull(resultSet.getBoolean(columnIndex++));

        if (icon != null) {

          setBeanValue(object, _DataObjectProperty.Icon, icon);
        }

        Object compentClass = null;

        compentClass = resultSet.getObject(columnIndex++);

        object.setCompentClassNull(resultSet.getBoolean(columnIndex++));

        if (compentClass != null) {

          setBeanValue(object, _DataObjectProperty.CompentClass, compentClass);
        }

        Object sortIndex = null;

        sortIndex = resultSet.getObject(columnIndex++);

        object.setSortIndexNull(resultSet.getBoolean(columnIndex++));

        if (sortIndex != null) {

          setBeanValue(object, _DataObjectProperty.SortIndex, sortIndex);
        }

        Object lastModifyUser = null;

        lastModifyUser = resultSet.getObject(columnIndex++);

        object.setLastModifyUserNull(resultSet.getBoolean(columnIndex++));

        if (lastModifyUser != null) {

          setBeanValue(object, _DataObjectProperty.LastModifyUser, lastModifyUser);
        }

        Object lastModifyTime = null;

        __dataType = resultSet.getMetaData().getColumnType(columnIndex);

        if (__dataType == java.sql.Types.DATE
            || __dataType == java.sql.Types.TIME
            || __dataType == java.sql.Types.TIMESTAMP) {
          lastModifyTime = resultSet.getTimestamp(columnIndex++);

        } else {
          lastModifyTime = resultSet.getObject(columnIndex++);
        }

        object.setLastModifyTimeNull(resultSet.getBoolean(columnIndex++));

        if (lastModifyTime != null) {

          setBeanValue(object, _DataObjectProperty.LastModifyTime, lastModifyTime);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object formCode = null;

        formCode = resultSet.getObject(columnIndex++);

        object.setFormCodeNull(resultSet.getBoolean(columnIndex++));

        if (formCode != null) {

          setBeanValue(object, _DataObjectProperty.FormCode, formCode);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
